#include "dialogFilter.h"

DialogFilter::DialogFilter(QWidget * parent)
{
    this->setWindowTitle("筛选");
    this->setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
    // .....
    this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
    this->setStyleSheet("QDialog{background-color: white; padding:20px; border: none; border: 10px solid rgb(200,219,243);}");

    _layout = new QVBoxLayout(this);
    _layout_hole = new QHBoxLayout(this);
    _layout_name = new QHBoxLayout(this);
    _layout_type = new QHBoxLayout(this);
    _layout_button = new QHBoxLayout(this);

    _button_yes = new QPushButton("确定", this);
    _button_no = new QPushButton("取消", this);

    _layout->addLayout(_layout_hole);
    _layout->addLayout(_layout_name);
    _layout->addLayout(_layout_type);
    _layout->addLayout(_layout_button);

    _lcBox_hole = new LLComboBox2(this);
    _lcBox_name = new LLComboBox2(this);
    _lcBox_type = new LLComboBox2(this);

    _layout->setMargin(40);
    _layout->setSpacing(15);
    _button_no->setFixedSize(QSize(130, 40));
    _button_no->setStyleSheet("background: #FFFFFF;\nborder-radius: 8px;\nborder: 1px solid #999999;");
    _button_yes->setFixedSize(QSize(130, 40));
    _button_yes->setStyleSheet("background-color: qlineargradient(x1: 0, y0: 0, x2: 0, y2: 1, stop: 0 #8C97ED, stop: 1 #0018D1);\nborder-radius: 8px; \ncolor: white;");

    _layout_hole->addWidget(new QLabel("孔位",this));
    _layout_hole->addWidget(_lcBox_hole);
    _layout_name->addWidget(new QLabel("样本名称",this));
    _layout_name->addWidget(_lcBox_name);
    _layout_type->addWidget(new QLabel("样本类型",this));
    _layout_type->addWidget(_lcBox_type);
    _layout_button->addWidget(_button_no);
    _layout_button->addWidget(_button_yes);

    connect(_button_yes, SIGNAL(clicked()), this, SLOT(on_yesClicked()));
    connect(_button_no, SIGNAL(clicked()), this, SLOT(on_noClicked()));


}

void DialogFilter::init(PCRState* state){

    if(!state) return;

    pState = state;
    try {
        // 孔位
        foreach(QString posi, pState->posiList){
            _lcBox_hole->addDataItem(posi);
        }

        // 样本名
        foreach(QString name, pState->nameList){
            _lcBox_name->addDataItem(name);
        }

        // 类型
        foreach(QString type, pState->typeList){
            _lcBox_type->addDataItem(type);
        }

    } catch (...) {
        qDebug() << __FUNCTION__ << "出现异常";
        return;
    }



}

void DialogFilter::on_yesClicked(){
    QStringList selectList;

    pState->posiList_filter.clear();
    selectList = this->_lcBox_hole->selectedDataText();
    foreach(QString selectItem, selectList){
        pState->posiList_filter.append(selectItem);
    }
    pState->nameList_filter.clear();
    selectList = this->_lcBox_name->selectedDataText();
    foreach(QString selectItem, selectList){
        pState->nameList_filter.append(selectItem);
    }
    pState->typeList_filter.clear();
    selectList = this->_lcBox_type->selectedDataText();
    foreach(QString selectItem, selectList){
        pState->typeList_filter.append(selectItem);
    }
    this->close();
    pState->emitFilterChanged();
}

void DialogFilter::on_noClicked(){
    this->close();
}
